package com.fs.core.security.config;

import com.fs.core.security.util.*;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.web.servlet.FilterRegistrationBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.stereotype.Component;

@Component
@Configuration
public class DBConfig {

    //是否对明文数据库用户名密码进行加密
    @Value("${encryptionDatasource:F}")
    private String encryptionDatasource;

    //是否通信数据传输安全模式
    @Value("${isTransSafe:F}")
    private String isTransSafe;

    //是否xss安全模式
    @Value("${isXssSafe:F}")
    private String isXssSafe;

    //是否csrf安全模式
    @Value("${isCsrfSafe:F}")
    private String isCsrfSafe;

    //是否model和token安全模式
    @Value("${isModelSafe:F}")
    private String isModelSafe;

    //解密密钥
    @Value("${decKey:useProInfo}")
    private String decKey;

    //加密类型
    @Value("${cryptType:1}")
    private String cryptType;

    //sm2加密模式
    @Value("${cipherMode:C1C3C2}")
    private String cipherMode;
    //待加密请求
    @Value("${encryptionRequest:}")
    private String encryptionRequest;

    //加密字段
    @Value("${base64Encryption:}")
    private String base64Encryption;


    //文件分布式存储方式  目前有三个模式  local、fastDFS、oss
    @Value("${fileSaveType:local}")
    private String fileSaveType;

    //是否是使用的达梦数据库
    @Value("${dataSourceModel:F}")
    private String dataSourceModel;

    //流转系统端口
    @Value("${lziport:8800}")
    private String lziport;

    //流转系统IP
    @Value("${lzip:127.0.0.1}")
    private String lzip;

    //是否是linux系统
    @Value("${system:window}")
    private String system;

    //openoffice的ip
    @Value("${openofficeip:127.0.0.1}")
    private String openofficeip;

    //域名地址的ip
    @Value("${domainName:127.0.0.1}")
    private String domainName;

    //允许的文件上传类型
    @Value("${allowedFileTypes:doc|docx}")
    private String allowedFileTypes;

    //host白名单添加
    @Value("${allowedServernames:}")
    private String allowedServernames;

    //是否动态数据源
    @Value("${dynamicDataSource:F}")
    private String dynamicDataSource;

    public DBConfig(){}

//    @Bean
//    public FilterRegistrationBean registerFilter() {
//
//        FilterRegistrationBean registration = new FilterRegistrationBean();
////        registration.setFilter(new DecryptionFilter());
//        registration.addUrlPatterns("/*");
//        registration.setName("DecryptionFilter");
//        registration.setOrder(1);
//        registration.setName("decryptionFilter");
//        registration.setOrder(0);
//        return registration;
//    }

    /**
     * 配置xss防范过滤器
     * @return
     */
//    @Bean
//    public FilterRegistrationBean xssFilterRegistration() {
//        FilterRegistrationBean registration = new FilterRegistrationBean();
//        registration.setFilter(new XssFilter());
//        registration.addUrlPatterns("/*");
//        registration.setName("xssFilter");
//        try{
//            registration.setName("xssFilter");
//        }catch (Exception e){
//            e.printStackTrace();
//        }
//
//        return registration;
//    }
    /**
     * 配置cookie防范过滤器
     * @return
     */
//    @Bean
//    public FilterRegistrationBean cookieFilterRegistration() {
//        FilterRegistrationBean registration = new FilterRegistrationBean();
////        registration.setFilter(new CookieFilter());
//        registration.addUrlPatterns("/*");
//        registration.setName("cookieFilter");
//        return registration;
//    }
    /**
     * 配置csrf防范过滤器
     * @return
     */
//    @Bean
//    public FilterRegistrationBean csrfFilterRegistration() {
//        FilterRegistrationBean registration = new FilterRegistrationBean();
////        registration.setFilter(new CsrfFilter());
//        registration.addUrlPatterns("/*");
//        registration.setName("csrfFilter");
//        return registration;
//    }
//    /**
//     * 配置文件过滤器
//     * @return
//     */
//    @Bean
//    public FilterRegistrationBean acceptFileFilterRegistration() {
//        FilterRegistrationBean registration = new FilterRegistrationBean();
//        registration.setFilter(new AcceptFileFilter());
//        registration.addUrlPatterns("/*");
//        registration.setName("acceptFileFilter");
//        return registration;
//    }

    public String getEncryptionDatasource() {
        return encryptionDatasource;
    }

    public void setEncryptionDatasource(String encryptionDatasource) {
        this.encryptionDatasource = encryptionDatasource;
    }

    public String getIsTransSafe() {
        return isTransSafe;
    }

    public void setIsTransSafe(String isTransSafe) {
        this.isTransSafe = isTransSafe;
    }

    public String getIsXssSafe() {
        return isXssSafe;
    }

    public void setIsXssSafe(String isXssSafe) {
        this.isXssSafe = isXssSafe;
    }

    public String getIsCsrfSafe() {
        return isCsrfSafe;
    }

    public void setIsCsrfSafe(String isCsrfSafe) {
        this.isCsrfSafe = isCsrfSafe;
    }

    public String getIsModelSafe() {
        return isModelSafe;
    }

    public void setIsModelSafe(String isModelSafe) {
        this.isModelSafe = isModelSafe;
    }

    public String getDecKey() {
        return decKey;
    }

    public void setDecKey(String decKey) {
        this.decKey = decKey;
    }

    public String getCryptType() {
        return cryptType;
    }

    public void setCryptType(String cryptType) {
        this.cryptType = cryptType;
    }

    public String getCipherMode() {
        return cipherMode;
    }

    public void setCipherMode(String cipherMode) {
        this.cipherMode = cipherMode;
    }

    public String getEncryptionRequest() {
        return encryptionRequest;
    }

    public void setEncryptionRequest(String encryptionRequest) {
        this.encryptionRequest = encryptionRequest;
    }

    public String getBase64Encryption() {
        return base64Encryption;
    }

    public void setBase64Encryption(String base64Encryption) {
        this.base64Encryption = base64Encryption;
    }

    public String getFileSaveType() {
        return fileSaveType;
    }

    public void setFileSaveType(String fileSaveType) {
        this.fileSaveType = fileSaveType;
    }

    public String getDataSourceModel() {
        return dataSourceModel;
    }

    public void setDataSourceModel(String dataSourceModel) {
        this.dataSourceModel = dataSourceModel;
    }

    public String getLziport() {
        return lziport;
    }

    public void setLziport(String lziport) {
        this.lziport = lziport;
    }

    public String getLzip() {
        return lzip;
    }

    public void setLzip(String lzip) {
        this.lzip = lzip;
    }

    public String getSystem() {
        return system;
    }

    public void setSystem(String system) {
        this.system = system;
    }

    public String getOpenofficeip() {
        return openofficeip;
    }

    public void setOpenofficeip(String openofficeip) {
        this.openofficeip = openofficeip;
    }

    public String getDomainName() {
        return domainName;
    }

    public void setDomainName(String domainName) {
        this.domainName = domainName;
    }

    public String getAllowedFileTypes() {
        return allowedFileTypes;
    }

    public void setAllowedFileTypes(String allowedFileTypes) {
        this.allowedFileTypes = allowedFileTypes;
    }

    public String getAllowedServernames() {
        return allowedServernames;
    }

    public void setAllowedServernames(String allowedServernames) {
        this.allowedServernames = allowedServernames;
    }

    public String getDynamicDataSource() {
        return dynamicDataSource;
    }

    public void setDynamicDataSource(String dynamicDataSource) {
        this.dynamicDataSource = dynamicDataSource;
    }
}

